package com.ruoyi.customer.api.factory;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.customer.api.RemoteCustomerService;
import com.ruoyi.customer.api.domain.CustomerManagement;
import com.ruoyi.customer.api.domain.WxLoginBody;
import com.ruoyi.system.api.domain.ShippingAddress;
import com.ruoyi.system.api.model.LoginUser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;

public class RemoteCustomerFallbackFactory implements FallbackFactory<RemoteCustomerService> {

    private static final Logger log = LoggerFactory.getLogger(RemoteCustomerFallbackFactory.class);
    @Override
    public RemoteCustomerService create(Throwable throwable) {
        log.error("用户服务调用失败:{}", throwable.getMessage());
        return new RemoteCustomerService()
        {
            @Override
            public R<Boolean> registerCustomerInfo(CustomerManagement sysUser, String source) {
                return R.fail("注册用户失败:" + throwable.getMessage());
            }

            @Override
            public R<LoginUser> getCustomerInfo(String account, String source) {
                return R.fail("获取用户失败:" + throwable.getMessage());
            }

            @Override
            public R<LoginUser> getCustomerInfoByOpenId(WxLoginBody wxLoginBody, String source) {
                return R.fail("微信登录获取用户失败:" + throwable.getMessage());
            }


            @Override
            public R<Boolean> recordCustomerLogin(CustomerManagement customerManagement, String source) {
                return R.fail("记录用户登录信息失败:" + throwable.getMessage());
            }

            @Override
            public R<ShippingAddress> getAddressInfo(Long id, String source) {
                return R.fail("获取客户收货地址失败:" + throwable.getMessage());
            }

            @Override
            public R<CustomerManagement> getInfoByPhoneNumber(String phoneNumber, String source) {
                return R.fail("获取用户失败:" + throwable.getMessage());
            }
            @Override
            public R<CustomerManagement> getInfoById(Long id, String source) {
                return R.fail("获取用户失败:" + throwable.getMessage());
            }

        };
    }
}
